
def createGenerator():
    mylist = range(3)
    for i in mylist:
        yield i*i

mygenerator = createGenerator()
print(mygenerator)

for i in mygenerator:
    print i
    
for p in mygenerator:
    print p
    
#list comprehension
a = [10, 21, 23, 11, 24]
print [val+1 for val in a]

#list comprehension with filter
print [val+1 for val in a if val > 15]

pairs = [(0, 'a'), (1, 'b'), (2, 'c')]

#two or more loop variable can be used
for index, value in pairs:
    print index, value

#enumerate -> index, item.    
y = ['a', 'b', 'c']
for index, value in enumerate(y):
    print index, value
    
#zip 2 or more sequences
#into list of "tuples"

x = [0, 1, 2]
y = ['a', 'b', 'c']

for idx, val in zip(x, y):
    print idx, val
